import { Module } from '@nestjs/common'
import { ConfigModule, ConfigService } from '@nestjs/config'
import { RedisModule as _RedisMoudle } from 'nestjs-redis'
import { ConfigurationKeys } from 'src/config/resources'
import { RedisService } from './redis.service'

@Module({
  imports: [
    _RedisMoudle.forRootAsync({
      imports: [ConfigModule],
      useFactory: (config: ConfigService<ConfigurationKeys>) => {
        const { port, host, password, db } = config.get('redis')
        return {
          port,
          host,
          password,
          db,
        }
      },
      inject: [ConfigService],
    })
  ],
  providers: [RedisService],
  exports: [RedisService]
})
export class RedisModule { }
